package net.qhzw.common.util;


/***
 * 经纬度 度分秒转换为小数
 */
public class DuFenMiaoToLonLat {

    public static double DuFenMiaoToLat(String latlng) {
        /*double du = Double.parseDouble(latlng.substring(0, latlng.indexOf("°")));
        double fen = Double.parseDouble(latlng.substring(latlng.indexOf("°") + 1, latlng.indexOf("′")));
        double miao = Double.parseDouble(latlng.substring(latlng.indexOf("′") + 1, latlng.indexOf("″")));*/

        double du = Double.parseDouble(latlng.substring(0,2));
        double fen = Double.parseDouble(latlng.substring(2,4));
        double miao = Double.parseDouble(latlng.substring(4,6));

        if (du < 0)
            return -(Math.abs(du) + (fen + (miao / 60)) / 60);
        return du + (fen + (miao / 60)) / 60;
    }
    public static double DuFenMiaoToLon(String latlng) {
        double du = Double.parseDouble(latlng.substring(0,3));
        double fen = Double.parseDouble(latlng.substring(3,5));
        double miao = Double.parseDouble(latlng.substring(5,7));
        if (du < 0)
            return -(Math.abs(du) + (fen + (miao / 60)) / 60);
        return du + (fen + (miao / 60)) / 60;
    }

    public static void main(String[] args) {
        String lon = "1243613";
        String lat = "400621";
        System.out.println(DuFenMiaoToLon(lon));
        System.out.println(DuFenMiaoToLat(lat));
    }





}
